<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="addtime">
      <el-input v-model="dataForm.addTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="deletestatus">
      <el-input v-model="dataForm.deletestatus" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="finishtime">
      <el-input v-model="dataForm.finishtime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="纯订单总价" prop="goodsAmount">
      <el-input v-model="dataForm.goodsAmount" placeholder="纯订单总价"></el-input>
    </el-form-item>
    <el-form-item label="" prop="invoice">
      <el-input v-model="dataForm.invoice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="invoicetype">
      <el-input v-model="dataForm.invoicetype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="msg">
      <el-input v-model="dataForm.msg" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orderId">
      <el-input v-model="dataForm.orderId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="10:待付 20:代发 30:已发 40:已收 50:已完  0:已取 100:已删" prop="orderStatus">
      <el-input v-model="dataForm.orderStatus" placeholder="10:待付 20:代发 30:已发 40:已收 50:已完  0:已取 100:已删"></el-input>
    </el-form-item>
    <el-form-item label="" prop="paytime">
      <el-input v-model="dataForm.paytime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="payMsg">
      <el-input v-model="dataForm.payMsg" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="refund">
      <el-input v-model="dataForm.refund" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="refundType">
      <el-input v-model="dataForm.refundType" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="shipcode">
      <el-input v-model="dataForm.shipcode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="shiptime">
      <el-input v-model="dataForm.shiptime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="shipPrice">
      <el-input v-model="dataForm.shipPrice" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="订单总价+运费" prop="totalprice">
      <el-input v-model="dataForm.totalprice" placeholder="订单总价+运费"></el-input>
    </el-form-item>
    <el-form-item label="" prop="addrId">
      <el-input v-model="dataForm.addrId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="设置默认的支付方式为支付宝" prop="paymentId">
      <el-input v-model="dataForm.paymentId" placeholder="设置默认的支付方式为支付宝"></el-input>
    </el-form-item>
    <el-form-item label="" prop="storeId">
      <el-input v-model="dataForm.storeId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="userId">
      <el-input v-model="dataForm.userId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="autoConfirmEmail">
      <el-input v-model="dataForm.autoConfirmEmail" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="autoConfirmSms">
      <el-input v-model="dataForm.autoConfirmSms" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="transport">
      <el-input v-model="dataForm.transport" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="outOrderId">
      <el-input v-model="dataForm.outOrderId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="ecId">
      <el-input v-model="dataForm.ecId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="ciId">
      <el-input v-model="dataForm.ciId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orderSellerIntro">
      <el-input v-model="dataForm.orderSellerIntro" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="returnShipcode">
      <el-input v-model="dataForm.returnShipcode" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="returnEcId">
      <el-input v-model="dataForm.returnEcId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="returnContent">
      <el-input v-model="dataForm.returnContent" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="returnShiptime">
      <el-input v-model="dataForm.returnShiptime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="orderType">
      <el-input v-model="dataForm.orderType" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="total_integral" prop="totalIntegral">
      <el-input v-model="dataForm.totalIntegral" placeholder="total_integral"></el-input>
    </el-form-item>
    <el-form-item label="订单收货地址" prop="deliveryAddress">
      <el-input v-model="dataForm.deliveryAddress" placeholder="订单收货地址"></el-input>
    </el-form-item>
    <el-form-item label="订单邀请人" prop="orderInviterId">
      <el-input v-model="dataForm.orderInviterId" placeholder="订单邀请人"></el-input>
    </el-form-item>
    <el-form-item label="" prop="deliveryaddress">
      <el-input v-model="dataForm.deliveryaddress" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          addTime: '',
          deletestatus: '',
          finishtime: '',
          goodsAmount: '',
          invoice: '',
          invoicetype: '',
          msg: '',
          orderId: '',
          orderStatus: '',
          paytime: '',
          payMsg: '',
          refund: '',
          refundType: '',
          shipcode: '',
          shiptime: '',
          shipPrice: '',
          totalprice: '',
          addrId: '',
          paymentId: '',
          storeId: '',
          userId: '',
          autoConfirmEmail: '',
          autoConfirmSms: '',
          transport: '',
          outOrderId: '',
          ecId: '',
          ciId: '',
          orderSellerIntro: '',
          returnShipcode: '',
          returnEcId: '',
          returnContent: '',
          returnShiptime: '',
          orderType: '',
          totalIntegral: '',
          deliveryAddress: '',
          orderInviterId: '',
          deliveryaddress: ''
        },
        dataRule: {
          addTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          deletestatus: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          finishtime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          goodsAmount: [
            { required: true, message: '纯订单总价不能为空', trigger: 'blur' }
          ],
          invoice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          invoicetype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          msg: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '10:待付 20:代发 30:已发 40:已收 50:已完  0:已取 100:已删不能为空', trigger: 'blur' }
          ],
          paytime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          payMsg: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          refund: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          refundType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          shipcode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          shiptime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          shipPrice: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          totalprice: [
            { required: true, message: '订单总价+运费不能为空', trigger: 'blur' }
          ],
          addrId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          paymentId: [
            { required: true, message: '设置默认的支付方式为支付宝不能为空', trigger: 'blur' }
          ],
          storeId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          autoConfirmEmail: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          autoConfirmSms: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          transport: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          outOrderId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          ecId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          ciId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderSellerIntro: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          returnShipcode: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          returnEcId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          returnContent: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          returnShiptime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderType: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          totalIntegral: [
            { required: true, message: 'total_integral不能为空', trigger: 'blur' }
          ],
          deliveryAddress: [
            { required: true, message: '订单收货地址不能为空', trigger: 'blur' }
          ],
          orderInviterId: [
            { required: true, message: '订单邀请人不能为空', trigger: 'blur' }
          ],
          deliveryaddress: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/orderform/shoppingorderform/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.addTime = data.shoppingOrderform.addTime
                this.dataForm.deletestatus = data.shoppingOrderform.deletestatus
                this.dataForm.finishtime = data.shoppingOrderform.finishtime
                this.dataForm.goodsAmount = data.shoppingOrderform.goodsAmount
                this.dataForm.invoice = data.shoppingOrderform.invoice
                this.dataForm.invoicetype = data.shoppingOrderform.invoicetype
                this.dataForm.msg = data.shoppingOrderform.msg
                this.dataForm.orderId = data.shoppingOrderform.orderId
                this.dataForm.orderStatus = data.shoppingOrderform.orderStatus
                this.dataForm.paytime = data.shoppingOrderform.paytime
                this.dataForm.payMsg = data.shoppingOrderform.payMsg
                this.dataForm.refund = data.shoppingOrderform.refund
                this.dataForm.refundType = data.shoppingOrderform.refundType
                this.dataForm.shipcode = data.shoppingOrderform.shipcode
                this.dataForm.shiptime = data.shoppingOrderform.shiptime
                this.dataForm.shipPrice = data.shoppingOrderform.shipPrice
                this.dataForm.totalprice = data.shoppingOrderform.totalprice
                this.dataForm.addrId = data.shoppingOrderform.addrId
                this.dataForm.paymentId = data.shoppingOrderform.paymentId
                this.dataForm.storeId = data.shoppingOrderform.storeId
                this.dataForm.userId = data.shoppingOrderform.userId
                this.dataForm.autoConfirmEmail = data.shoppingOrderform.autoConfirmEmail
                this.dataForm.autoConfirmSms = data.shoppingOrderform.autoConfirmSms
                this.dataForm.transport = data.shoppingOrderform.transport
                this.dataForm.outOrderId = data.shoppingOrderform.outOrderId
                this.dataForm.ecId = data.shoppingOrderform.ecId
                this.dataForm.ciId = data.shoppingOrderform.ciId
                this.dataForm.orderSellerIntro = data.shoppingOrderform.orderSellerIntro
                this.dataForm.returnShipcode = data.shoppingOrderform.returnShipcode
                this.dataForm.returnEcId = data.shoppingOrderform.returnEcId
                this.dataForm.returnContent = data.shoppingOrderform.returnContent
                this.dataForm.returnShiptime = data.shoppingOrderform.returnShiptime
                this.dataForm.orderType = data.shoppingOrderform.orderType
                this.dataForm.totalIntegral = data.shoppingOrderform.totalIntegral
                this.dataForm.deliveryAddress = data.shoppingOrderform.deliveryAddress
                this.dataForm.orderInviterId = data.shoppingOrderform.orderInviterId
                this.dataForm.deliveryaddress = data.shoppingOrderform.deliveryaddress
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/orderform/shoppingorderform/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'addTime': this.dataForm.addTime,
                'deletestatus': this.dataForm.deletestatus,
                'finishtime': this.dataForm.finishtime,
                'goodsAmount': this.dataForm.goodsAmount,
                'invoice': this.dataForm.invoice,
                'invoicetype': this.dataForm.invoicetype,
                'msg': this.dataForm.msg,
                'orderId': this.dataForm.orderId,
                'orderStatus': this.dataForm.orderStatus,
                'paytime': this.dataForm.paytime,
                'payMsg': this.dataForm.payMsg,
                'refund': this.dataForm.refund,
                'refundType': this.dataForm.refundType,
                'shipcode': this.dataForm.shipcode,
                'shiptime': this.dataForm.shiptime,
                'shipPrice': this.dataForm.shipPrice,
                'totalprice': this.dataForm.totalprice,
                'addrId': this.dataForm.addrId,
                'paymentId': this.dataForm.paymentId,
                'storeId': this.dataForm.storeId,
                'userId': this.dataForm.userId,
                'autoConfirmEmail': this.dataForm.autoConfirmEmail,
                'autoConfirmSms': this.dataForm.autoConfirmSms,
                'transport': this.dataForm.transport,
                'outOrderId': this.dataForm.outOrderId,
                'ecId': this.dataForm.ecId,
                'ciId': this.dataForm.ciId,
                'orderSellerIntro': this.dataForm.orderSellerIntro,
                'returnShipcode': this.dataForm.returnShipcode,
                'returnEcId': this.dataForm.returnEcId,
                'returnContent': this.dataForm.returnContent,
                'returnShiptime': this.dataForm.returnShiptime,
                'orderType': this.dataForm.orderType,
                'totalIntegral': this.dataForm.totalIntegral,
                'deliveryAddress': this.dataForm.deliveryAddress,
                'orderInviterId': this.dataForm.orderInviterId,
                'deliveryaddress': this.dataForm.deliveryaddress
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
